from Client import Client

from gevent import monkey
monkey.patch_all()      # 用于将标准库中大部分阻塞式调用修改为协作式运行
import gevent


def start_client(rece_file='./reced_file'):
    c = Client()
    c.recv(rece_file, './file')


def start_server1():
    from Server1 import Server
    s = Server()
    s.start()


def start_server2():
    from Server2 import Server
    s = Server()
    s.start()


def start_server3():
    from Server3 import Server
    s = Server()
    s.start()


def test_server1():
    g1 = gevent.spawn(start_client)
    g2 = gevent.spawn(start_server1)
    gevent.joinall([g2, g1])


def test_server2():
    g = gevent.spawn(start_server2)
    client_line = [gevent.spawn(start_client, './reced_{}'.format(i)) for i in range(10)]
    client_line.append(g)
    gevent.joinall(client_line)


def test_server3():
    g = gevent.spawn(start_server3)
    client_line = [gevent.spawn(start_client, './reced_{}'.format(i)) for i in range(10)]
    client_line.append(g)
    gevent.joinall(client_line)


if __name__ == '__main__':
    # test_server1()
    # test_server2()
    test_server3()